﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukou.Dao.Impl;
using Dukou.Security.Domain;
using NHibernate;

namespace Dukou.Security.Dao.Impl
{
    public class UserDao : NHibernateDao<User, Int64>, IUserDao
    {
        public User FindByName(string name)
        {
            return this.HibernateTemplate.Execute<User>(delegate(ISession session) 
            {
                var users = session.CreateQuery("from User u where u.Name = ?")
                    .SetParameter(0, name)
                    .List<User>();
                return users.FirstOrDefault();
            });
        }

        public User FindByEmail(string email)
        {
            return this.HibernateTemplate.Execute<User>(delegate(ISession session)
            {
                var users = session.CreateQuery("from User u where u.Email = ?")
                    .SetParameter(0, email)
                    .List<User>();
                return users.FirstOrDefault();
            });
        }
    }
}
